package validation;

import java.text.SimpleDateFormat;
import java.util.Date;

import dbmanager.DBManager;

public class Et implements Validation
{
	String ConditionValue; 

	public boolean validate (String Value, String ConditionValue)
	{
	try
		{
			//INTEGER, FLOAT, DOUBLE, LONG, ETC.
			double val = Double.parseDouble(Value);
			double convalue = Double.parseDouble(ConditionValue);
			
			if (val == convalue)
			{
				return true;
			}
			else
				return false;
		} 
		catch (NumberFormatException e) 
		{
			//STRING
			if(Value.toLowerCase().equals(ConditionValue.toLowerCase()))
				return true;
			//DATE
			else
			{
				try
				{
					if(Value.length()==ConditionValue.length())
					{
						String pattern = "yyyy-MM-dd HH:MM:ss";
						SimpleDateFormat sdm = new SimpleDateFormat(pattern);
						Date date_value;
						try 
						{
							date_value = (Date)sdm.parse(Value);
						}
						catch (Exception e1) {
							Value = Value+" 00:00:00";
							date_value = (Date)sdm.parse(Value);
						}
						
						Date date_condition;
						try
						{
							date_condition = (Date)sdm.parse(ConditionValue);
						} catch (Exception e1) {
							ConditionValue = ConditionValue+" 00:00:00";
							date_condition = (Date)sdm.parse(ConditionValue);
						}
						
						if(date_value.compareTo(date_condition)==0)
							return true;
						else
							return false;
					}
					else
					{
						String pattern = "yyyy-MM-dd";
						SimpleDateFormat sdm = new SimpleDateFormat(pattern);
						Date date_value = (Date)sdm.parse(Value);
						Date date_condition = (Date)sdm.parse(ConditionValue);
						
						if(date_value.compareTo(date_condition)==0)
							return true;
						else
							return false;
					}
				}
				catch (Exception e1) 
				{
					e.printStackTrace();
				}
			}
				
				
		}
		return false;
	}
	public boolean validate(String Value)
	{
		// TODO Auto-generated method stub
		return false;
	}
	public String getMessage() 
	{
		// TODO Auto-generated method stub
		return "The value must be equals to "+ConditionValue;
	}
	
	public static void main (String args[])
	{
		Et et = new Et();
		System.out.println("Validate : "+et.validate("100", "100"));
		System.out.println("Validate : "+et.validate("24", "100"));
	}

	public void setDbmanager(DBManager database) {
		// TODO Auto-generated method stub
		
	}

	public boolean validate(String Value, String ConditionValue, String Refvalue) 
	{
		return validate(Value,ConditionValue);
	}

	public void setBasicvalue(String value) 
	{
		
	}
}
